package cmc.asiainfo.com.xiht_bmap;

import android.content.Context;

import com.baidu.mapapi.SDKInitializer;

/**
 * @Author xihaitao
 * @Date 2017/2/9
 * @Function:
 *      百度地图公共工具类
 */

public class BaiduMapUtil {

    private static final String TAG = BaiduMapUtil.class.getSimpleName();

    /**
     * @Author 席海涛[xiht@asiainfo.com]
     * @Date 2017/2/10 9:19
     * @Function:
     *      单例模式
     */
    private static BaiduMapUtil instance;

    public static BaiduMapUtil getInstance() {
        if (instance == null) {
            instance = new BaiduMapUtil();
        }
        return instance;
    }


    /**
     * @Author 席海涛[xiht@asiainfo.com]
     * @Date 2017/2/9 15:26
     * @Function:
     *      此处的入参context必须为ApplicationContext
     *      初始化百度地图组件，获取传入ApplicationContext，为设置地图提供后续参数
     */
    public void mapLibInit(Context context) {
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        //注意该方法要再setContentView方法之前实现
        SDKInitializer.initialize(context);

        setApplicationContext(context);
    }

    /**
     * @Author 席海涛[xiht@asiainfo.com]
     * @Date 2017/2/9 16:29
     * @Function:
     *      获取ApplicationContext
     */
    private Context applicationContext;

    public void setApplicationContext(Context applicationContext) {
        if (applicationContext != null) {
            this.applicationContext = applicationContext;
        }
    }

    public Context getApplicationContext() {
        return this.applicationContext;
    }

}
